package com.tfjybj.itoo.teach.provider.service.impl;

import com.dmsdbj.itoo.tool.base.service.impl.BaseServicePlusImpl;
import com.dmsdbj.itoo.tool.itooexception.ItooRuntimeException;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.tfjybj.itoo.teach.entity.StaffInstitutionEntity;
import com.tfjybj.itoo.teach.model.StaffInstitutionModel;
import com.tfjybj.itoo.teach.provider.dao.StaffInstitutionDao;
import com.tfjybj.itoo.teach.provider.service.StaffInstitutionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * StaffInstitutionService接口实现类
 * ${base}表
 *
 * @author 田成荣
 * @version 2.0.0
 * @since 2.0.0 2018-11-08 19:34:10
 */
@Slf4j
@Service("staffInstitutionService")
public class StaffInstitutionServiceImpl extends BaseServicePlusImpl<StaffInstitutionDao, StaffInstitutionEntity> implements StaffInstitutionService {
	
	//region 模板生成
    @Resource
    private StaffInstitutionDao staffInstitutionDao;

	
	 @Override
    public PageInfo<StaffInstitutionEntity> queryByLikeStaffId(String staffId, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        return new PageInfo<>(staffInstitutionDao.queryLikeStaffId(staffId));
    }
	//endregion

    /**
     * 更新教师主要机构
     *
     * @param staffId 教师编码
     * @param academyId 机构ID
     * @return 更新成功或失败
     * @author 张家豪
     * @since 2018.11.23 23:05
     */
    @Override
    public boolean updateByStaffIdAndIsmain(String staffId,String academyId){
        int successCount;
        try {
            successCount = staffInstitutionDao.updateByStaffIdAndIsmain(staffId,academyId);
        } catch (Exception e) {
            log.error("impl",e);
            throw new ItooRuntimeException(e);
        }
        return successCount != 0;

    }

    /* **********************************以下为非模板生成的内容********************************* */

    /**
     * 删除该教师的所有附属机构
     *
     * @param staffId 教师编码
     * @return 更新成功或失败
     * @author 张家豪
     * @since 2018年11月24日22:55:01
     */
    @Override
    public boolean deleteSubAcademy(String staffId){
        int successCount;
        try {
            successCount = staffInstitutionDao.deleteSubAcademy(staffId);
        } catch (Exception e) {
            log.error("impl",e);
            throw new ItooRuntimeException(e);
        }
        return successCount != 0;
    }

    @Override
    public List<StaffInstitutionModel> queryCollege(String userId) {
        return staffInstitutionDao.queryCollege(userId);
    }
}
